package com.code.leetcode.offer;

import com.code.leetcode.utils.TreeNode;
import sun.reflect.generics.tree.Tree;

import java.util.ArrayList;
import java.util.List;

/**
 * @author codeDorado
 * @version 1.0
 * @date 2020/8/4 10:14
 */
public class The54 {

    List<Integer> list = new ArrayList<>();

    public int kthLargest(TreeNode root, int k) {
        dfs(root);
        Integer[] ints = new Integer[list.size()];
        list.toArray(ints);
        return ints[ints.length - k];
    }

    private void dfs(TreeNode node) {
        if (node == null) return;
        dfs(node.left);
        list.add(node.val);
        dfs(node.right);
    }


}
